package com.limou.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.limou.mapper.EmployeeMapper;
import com.limou.pojo.EmpJob;
import com.limou.pojo.Employee;
import com.limou.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    //查询所有员工
    @Override
    public List<Employee> findAllEmployee() {
        List<Employee> employeeList = employeeMapper.findAllEmployee();
        return employeeList;
    }

    //添加员工
    @Override
    public void addEmployee(Employee employee) {
        employeeMapper.addEmployee(employee);
    }

    @Override
    public Employee findAllEmployeeById(int id) {
        Employee employee = employeeMapper.findAllEmployeeById(id);
        return employee;
    }

    @Override
    public void updateEmployee(Employee employee) {
        employeeMapper.updateEmployee(employee);
    }

    @Override
    public void deleteEmployee(Employee employee) {
        employeeMapper.deleteEmployee(employee);
    }

    @Override
    public List<Employee>  findEmployeeByName(String name) {
        List<Employee> employeeByName = employeeMapper.findEmployeeByName(name);
        return employeeByName;
    }

    @Override
    public PageInfo<Employee> getEmployeePage(Integer pageNum) {
/*
1.开启分页功能
参数：
（1）pageNum由前端传入
（2）pageSize每页显示的数据条数
 */
        PageHelper.startPage(pageNum,4);

        //查询所有员工
        List<Employee> employeeList = employeeMapper.findAllEmployee();

        System.out.println(employeeList+"service......");
        //进行分页操作
        /*
        参数：
        1：传入employeeList
        2：前后显示
         */
        PageInfo<Employee> employeePageInfo = new PageInfo<>(employeeList, 5);
        return employeePageInfo;

    }

    @Override
    public List<Employee> findEmployeeJob() {
      List<Employee> list = employeeMapper.findEmployeeJob();

        return list;
    }

    @Override
    public void deleteEmpJobById(int empId) {
        employeeMapper.deleteEmpJobById(empId);

    }

    @Override
    public void insertEmpJobById(EmpJob empJob) {
        employeeMapper.insertEmpJobById(empJob);

    }

}
